class Solution
{
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2)
    {
        vector<int>::iterator cur = arr1.begin();
        for (auto e : arr2)
        {
            while (*cur == e)
                ++cur;
            if (cur != arr1.end())
            {
                auto seek = cur + 1;
                while (seek != arr1.end())
                {
                    if (*seek == e)
                    {
                        swap(*cur, *seek);
                        ++cur;
                    }
                    ++seek;
                }
            }
        }
        sort(cur, arr1.end());

        return arr1;
    }
};
